package org.jeecg.modules.demo.com.kunpeng.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.com.kunpeng.entity.SupplierClassification;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceCode;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceException;
import org.jeecg.modules.demo.com.kunpeng.mapper.SupplierClassificationMapper;
import org.jeecg.modules.demo.com.kunpeng.service.ISupplierClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 供应商分类表
 * @Author: jeecg-boot
 * @Date:   2023-01-09
 * @Version: V1.0
 */
@Service
public class SupplierClassificationServiceImpl extends ServiceImpl<SupplierClassificationMapper, SupplierClassification> implements ISupplierClassificationService {

    @Autowired
    private SupplierClassificationMapper supplierClassificationMapper;


    /**
     * 新增
     * @param supplierClassification
     */
    @Override
    public void insert(SupplierClassification supplierClassification) {
        List<SupplierClassification> supplierClassifications = supplierClassificationMapper.queryListBySupplierClass(supplierClassification.getSupplierClassification());
        if(supplierClassifications.size()>0){
            String message="该供货商分类已存在,请重新填写！";
            throw new ServiceException(ServiceCode.ERR_CONFLICT,message);
        }
        supplierClassificationMapper.insert(supplierClassification);
    }

    /**
     * 供应商分类列表
     * @return
     */
    @Override
    public List<String> supplierClassificationList() {
        List<String> supplierClassificationList = supplierClassificationMapper.supplierClassificationList();
        return supplierClassificationList;
    }


    /**
     * 分类模糊查询
     * @param page
     * @param keyWords
     * @return
     */
    @Override
    public Page<SupplierClassification> queryListByClass(Page<SupplierClassification> page, String keyWords) {
        Page<SupplierClassification> supplierClassificationPage = page.setRecords(supplierClassificationMapper.queryListByClass(page, keyWords));
        return supplierClassificationPage;
    }
}
